home *** CD-ROM | disk | FTP | other *** search
- /*
- File: EnableSelfSendSample.c
- By: Rich Kubota
- Developer Technical Support
-
- Purpose: Demonstrate the use of the OTOptionManagement call to tell an AppleTalk
- endpoint to enable/disable the SelfSend option.
- change history:
- 1/25/98 rrk Changed the original use of the OTOptionManagement call, OPT_SELFSEND
- which only enables selfsend from the endpoint to other AppleTalk services when
- broadcast messages are sent from the endpoint. The desired behavior is one
- where if other AppleTalk clients on the node send broadcast messages, that they
- are also sent to the endpoint. To this end, there is the ATALK_IOC_FULLSELFSEND
- Ioct, which must be sent to the DDP endpoint.
-
- Note that the ATALK_IOC_FULLSELFSEND is desired to respond similarly to the
- PSetSelfSend function. If the result is not negative, then the following responses
- can be expected.
-
- 0 - FullSelfSend was previously off
- 1 - FullSelfSend was previously on
-
- Input parameters
-
- ep - the AppleTalk EndpointRef on which to enable fullSelfSend. You can pass
- any AppleTalk endpoint, DDP or above, to this function.
-
- enableSelfSend - a long word of the desired setting.
-
- Return result
- < 0 - error
- 0 - FullSelfSend was previously off
- 1 - FullSelfSend was previously on
-
- Note that if the use of the Ioctl returns an error < 0, then the PBSetSelfSend
- function is called.
-
- Note: As with the PSetSelfSend call, the Ioctl call affects AppleTalk globally.
- If you enable this feature, it is recommended that you not disable the feature
- when the process quits. The user may launch another process which enables
- selfsend. Turning off selfsend in this case, affects the other process, as well.
- */
-
- #include "OpenTransport.h" // open transport files
- #include "OpenTptAppletalk.h"
- #include "AppleTalk.h"
-
- extern OSStatus DoNegotiateSelfSendOption(EndpointRef ep, long enableSelfSend);
-
-
- /*
- Sample function to enable/disable the SelfSend option for
- an AppleTalk endpoint.
-
- Input
- EndpointRef ep - endpoint on which to set SelfSend option on
- long enableSelfSend - 1L - option on, 0L - option off
-
- Return: kOTNoError indicates that the option was successfully negotiated
- otherwise the error result is returned
-
- IMPORTANT NOTE: if you find that this sample fails to enable/disable self send, check
- the file OpenTptAppleTalk.h and ensure that ATALK_IOC_FULLSELFSEND is defined
- as follows
-
- #define ATALK_IOC_FULLSELFSEND MIOC_CMD(MIOC_ATALK,47)
-
- there are versions of the header file that incorrectly define
- ATALK_IOC_FULLSELFSEND as follows.
-
- #define ATALK_IOC_FULLSELFSEND MIOC_CMD(MIOC_ATALK,47) // INCORRECT
-
-
-
- */
- OSStatus DoNegotiateSelfSendOption(EndpointRef ep, long enableSelfSend)
-
- {
- OSStatus result;
- SetSelfparms pb;
- Boolean usePB = false;
-
- if (OTIsSynchronous(ep) == false) // check whether ep sync or not
- usePB = true;
- else
- {
- result = OTIoctl(ep, ATALK_IOC_FULLSELFSEND, (void*)enableSelfSend);
- if (result < kOTNoError)
- usePB = true; // if an error occured, try using the PBSetSelfSend call
- }
-
- if (usePB == true)
- {
- pb.newSelfFlag = enableSelfSend != 0 ? true : false; /* set self send option */
- result = PSetSelfSend((MPPPBPtr) &pb, false);
-
- }
-
- return result;
- }
-